<?php
/**
 * Created by PhpStorm.
 * User: beijingwhg
 * Date: 2017/5/9
 * Time: 下午5:46
 */

namespace App\Http\Middleware;

use App\Models\PowerModel;
use Closure;
use App\Models\RoleModel;
use Illuminate\Contracts\Auth\Factory as Auth;
use Illuminate\Support\Facades\Cache;

class AdminRole
{
    protected $role;

    protected $auth;

    protected $power;

    public function __construct(RoleModel $roleModel, Auth $auth, PowerModel $powerModel)
    {
        $this->role = $roleModel;

        $this->power = $powerModel;

        $this->auth = $auth->guard('admin');
    }

    public function handle($request, Closure $next)
    {
        //获取当前请求内容
        $route = url2Route($request->getRequestUri());
        //无权限则跳转
        if ($route && !ifPermit($route)) {
            return redirect('/admin/np');
        }
        return $next($request);
    }
}